#include "elementselector.h"
#include <QMouseEvent>
#include <QtOpenGL>
#include <Renderer>
#include <Core>
#include "application.h"
#include "src/drawingview.h"
#include <Document>

ElementSelector::ElementSelector(SelectionType selType, QObject *parent) :
    QObject(parent)
  , m_selectionType(selType)
{
}

QPainterPath ElementSelector::selectedArea() const
{
    return QPainterPath();
}

void ElementSelector::mousePress(QMouseEvent *pEvent)
{
    float oneOverZoom = 1.0f/Application::app().activeDocument()->zoom();

    switch(m_selectionType)
    {
    case Rectangle: m_rect = QRect(pEvent->pos()*oneOverZoom, QSize()); break;
    }
}

void ElementSelector::mouseMove(QMouseEvent *pEvent)
{
    float oneOverZoom = 1.0f/Application::app().activeDocument()->zoom();

    switch(m_selectionType)
    {
    case Rectangle: m_rect.setBottomRight(pEvent->pos()*oneOverZoom);
                    break;
    }
}

void ElementSelector::mouseRelease(QMouseEvent *pEvent)
{
    float oneOverZoom = 1.0f/Application::app().activeDocument()->zoom();

    switch(m_selectionType)
    {
    case Rectangle: m_rect.setBottomRight(pEvent->pos()*oneOverZoom);
                    break;
    }
}

void ElementSelector::draw() const
{
    Renderer::LineStyle dotedLine;
    dotedLine.factor = 2;
    dotedLine.pattern = 0xAAAA;

    switch(m_selectionType)
    {
    case Rectangle:
        Core::instance().renderer()->drawRect(m_rect, QColor(255, 255, 0), 1, &dotedLine);
        break;
    }
}

void ElementSelector::setSelectionType(ElementSelector::SelectionType type)
{
    m_selectionType = type;
}
